<?php
if(file_exists('code.pfx.lock')&&$_REQUEST['restall']!='yes'){
reload_js('请先重命名code.pfx.lock后，再继续操作','index.php');
exit();
}
set_time_limit(0);
ini_set('memory_limit','128M');
if(mysql_error()){showinfo(mysql_error());exit();}
function showinfo($str){
	echo "<script language='javascript'>document.getElementById('notice').innerHTML='".addslashes($str)."';</script>";
}
if($_REQUEST['restall']=='yes'){
	if(mysql_query("select id from ".$prefix."websetting")){
		$do=file_get("\x68tt\x70:\x2f\x2f\x77\x77w.f\x65\x6egs\x688.co\x6d/s\x71\x6d/ch\x65ck_s\x71m.\x70hp?\x75ser\x6e\x61me=".$_REQUEST['username']."&\x61\x70\x70S\x65cr\x65t=".$_REQUEST['appSecret']."&do\x6d\x61\x69\x6e=".$_SERVER['SERVER_NAME']."&t=".$type);
		if($do){
			showinfo($do);
			exit();
		}else{
			dropAllTable();
		}
	}else{
		showinfo("重新安装失败！请确保数据库中存在站点相关数据，否则将不能重新安装");exit();
	}
}
$xml=file_get("\x68tt\x70:\x2f\x2f\x77\x77w.f\x65\x6egs\x688.co\x6d/s\x71\x6d/ch\x65ck_s\x71m.\x70hp?\x75ser\x6e\x61me=".$_REQUEST['username']."&\x61\x70\x70S\x65cr\x65t=".$_REQUEST['appSecret']."&t=".$type);
if($xml){
	if(!file_put_contents("t\x65\x6d\x70.x\x6dl",$xml)){
	showinfo('请将install目录权限设置为可写或777后重试');
	unlink("t\x65\x6d\x70.x\x6dl");
	exit();
	}
	$dom = new DomDocument();
	$dom->load("t\x65\x6d\x70.x\x6dl");
	unlink("t\x65\x6d\x70.x\x6dl");
	$return = $dom->getElementsByTagName("status")->item(0)->nodeValue ;
	if($return==2){
	if($_GET['cover']=='yes'){
	dropAllTable();
	}
	$sqm = $dom->getElementsByTagName("sqm")->item(0)->nodeValue ;
	$filetxt=file_get("code.pfx");
	$sql=passport_decrypt($filetxt,$sqm);
	$sql=get_create_sql($sql);
	if(!mysql_query($sql)){
		if(mysql_num_rows(mysql_query("select * from ".$prefix."websetting"))){
			showinfo("<div align=center>安装失败，原因：表".$prefix."websetting已存在，是否<a href='?step=3&restall=".$_REQUEST['restall']."&cover=yes&username=".$_REQUEST['username']."&\x61\x70\x70S\x65cr\x65t=".$_REQUEST['appSecret']."'>覆盖安装</a>，或修改conn.php中的参数</div>");
			if($_REQUEST['restall']){
				file_get("\x68tt\x70:\x2f\x2f\x77\x77w.f\x65\x6egs\x688.co\x6d/s\x71\x6d/ch\x65ck_s\x71m.\x70hp?\x75ser\x6e\x61me=".$_REQUEST['username']."&\x61\x70\x70S\x65cr\x65t=".$_REQUEST['appSecret']."&su=1&do\x6d\x61\x69\x6e=".$_SERVER['SERVER_NAME']."&t=".$type);
			}
		}else{
			showinfo("安装失败,如果您已经按照安装步骤进行安装，并已正确获得授权，则可以到<a href='http://www.fengsh8.com' target=_blank>风尚淘宝客官网</a>联系客服进行帮助。");
			if($_REQUEST['restall']){
				if(mysql_num_rows(mysql_query("select * from ".$prefix."websetting"))){
					file_get("\x68tt\x70:\x2f\x2f\x77\x77w.f\x65\x6egs\x688.co\x6d/s\x71\x6d/ch\x65ck_s\x71m.\x70hp?\x75ser\x6e\x61me=".$_REQUEST['username']."&\x61\x70\x70S\x65cr\x65t=".$_REQUEST['appSecret']."&su=1&do\x6d\x61\x69\x6e=".$_SERVER['SERVER_NAME']."&t=".$type);
				}
			}
		}
	}else{
	$sql=get_insert_sql();
	if(mysql_query($sql)&&import("f\x65\x6egs\x68_s\x68o\x70.s\x71l")){
	$str=file_get("\x68tt\x70:\x2f\x2f\x77\x77w.f\x65\x6egs\x688.co\x6d/s\x71\x6d/ch\x65ck_s\x71m.\x70hp?\x75ser\x6e\x61me=".$_REQUEST['username']."&\x61\x70\x70S\x65cr\x65t=".$_REQUEST['appSecret']."&su=1&do\x6d\x61\x69\x6e=".$_SERVER['SERVER_NAME']."&t=".$type);
	if($str){
	showinfo($str);
	if(!$_REQUEST['restall']){
	$str='if(str_replace("www.","",$_SERVER["SERVER_NAME"])!=base64_decode("'.base64_encode(str_replace("www.","",$_SERVER["SERVER_NAME"])).'")){echo(base64_decode("PGRpdiBhbGlnbj1jZW50ZXI+5pyq5o6I5p2D55So5oi377yM56iL5bqP5a6Y572R77yaPGEgaHJlZj0naHR0cDovL3d3dy5mZW5nc2g4LmNvbSc+d3d3LmZlbmdzaDguY29tPC9hPiDmvJTnpLrvvJo8YSBocmVmPSdodHRwOi8vd3d3LnRiaGFvZGlhbi5jbic+5reY5a6d5aW95bqXPC9hPjwvZGl2Pg=="));}';
	file_put_contents("../model/function.php",$str,FILE_APPEND);
	}
	if(!rename("\x63od\x65.\x70fx","\x63od\x65.\x70fx.lo\x63\x6b")){
		$str="alert('请将install目录下的code.pfx重命名为code.pfx.lock，然后再进入后台修改基本参数！');";
	}else{
		$str='';
	}
	echo "<script language='javascript'>installOver();".$str."</script>";
	}else{
	dropAllTable();
	showinfo("安装失败,如果您已经按照安装步骤进行安装，并已正确获得授权，则可以到<a href='http://www.fengsh8.com' target=_blank>官网</a>联系客服进行帮助。");
	}
	}else{
	if($_REQUEST['restall']){
	file_get("\x68tt\x70:\x2f\x2f\x77\x77w.f\x65\x6egs\x688.co\x6d/s\x71\x6d/ch\x65ck_s\x71m.\x70hp?\x75ser\x6e\x61me=".$_REQUEST['username']."&\x61\x70\x70S\x65cr\x65t=".$_REQUEST['appSecret']."&su=1&do\x6d\x61\x69\x6e=".$_SERVER['SERVER_NAME']."&t=".$type);
	}
	showinfo("<div align=center>安装失败，原因：".mysql_error()."。</div>");
	dropAllTable();
	}
	}
	}elseif($return==1){
	if($_REQUEST['restall']=='yes'){
	if(mysql_query("select * from ".$prefix."websetting")){
	file_get("\x68tt\x70:\x2f\x2f\x77\x77w.f\x65\x6egs\x688.co\x6d/s\x71\x6d/ch\x65ck_s\x71m.\x70hp?\x75ser\x6e\x61me=".$_REQUEST['username']."&\x61\x70\x70S\x65cr\x65t=".$_REQUEST['appSecret']."&su=1&do\x6d\x61\x69\x6e=".$_SERVER['SERVER_NAME']."&t=".$type);
	}
	}
	showinfo("安装失败，您的账户所绑定的授权码的可安装次数剩余 0 次，客服QQ：249917210");
	}else{
	if($_REQUEST['restall']=='yes'){
	if(mysql_query("select * from ".$prefix."websetting")){
	file_get("\x68tt\x70:\x2f\x2f\x77\x77w.f\x65\x6egs\x688.co\x6d/s\x71\x6d/ch\x65ck_s\x71m.\x70hp?\x75ser\x6e\x61me=".$_REQUEST['username']."&\x61\x70\x70S\x65cr\x65t=".$_REQUEST['appSecret']."&su=1&do\x6d\x61\x69\x6e=".$_SERVER['SERVER_NAME']."&t=".$type);
	}
	}
	showinfo("安装失败，对不起，您的账号未绑定任何授权码,获取授权客服QQ：249917210");
	}
}else{
	showinfo("获取数据失败，请联系空间商开启allow_url_fopen或者curl支持后重试！");
}
?>

